package com.example.permissionservice.controller;

import com.example.permissionservice.pojo.Resource;
import com.example.permissionservice.service.ResourceService;
import com.myprojects.common.dto.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping(value = "/resource-curd")
public class ResourceController {

    @Autowired
    ResourceService resourceService;

    /**
     * 该方法用于分页查询所有的用户信息(非员工)
     */
    @RequestMapping(value = "/resources",method = RequestMethod.GET)
    @ResponseBody
    public Msg getAllResources(){
        Msg result ;//要返回的结果
        try {
            List<Resource> resourceList = resourceService.selectAllResource();
            //生成返回成功的结果
            result = Msg.succeed();
            //将pageInfo加入返回的结果中
            result.addData("resourceList",resourceList);
            System.out.println(result.getDataMap());
        }catch (Exception e){
            e.printStackTrace();
            result = Msg.failed();
            result.setMsg("服务端处理异常!");
        }

        return result;
    }

}
